package com.wangjiyuan.giftshuo.ui.fragment.listtop.other;

import com.wangjiyuan.giftshuo.bean.listtopbean.commentbean.CommentBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.everydaybean.EveryDayBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.maybelikebean.MayBeLikeBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.singleproductbean.SingleProductBean;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.helper.OkHttp3Helper;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.interfaces.ListTopRetrofitInterface;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.message.UrlMessage;


import java.util.Map;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * Created by ZangSyeriong on 2016/11/15.
 *
 * 通过Retrofit获取网络数据，
 * 返回对象为Observable
 */

public class ListTopModel implements ListTopContract.IListTopModel{

    private Retrofit mRetrofit = null;

    @Override
    public Observable<EveryDayBean> getEveryDayData(int path, Map<String, String> params) {
        mRetrofit = new Retrofit.Builder()
                .baseUrl(UrlMessage.EVERYDAY_BASE_URL)
                .client(OkHttp3Helper.getOkHttpSingletonInstance())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        Observable<EveryDayBean> everyDayData = mRetrofit.create(
                ListTopRetrofitInterface.class).getEveryDayData(path, params);
        return everyDayData;
    }

    @Override
    public Observable<MayBeLikeBean> getMayBeLikeData(int path) {
        mRetrofit = new Retrofit.Builder()
                .baseUrl(UrlMessage.EVERYDAY_BASE_URL)
                .client(OkHttp3Helper.getOkHttpSingletonInstance())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        Observable<MayBeLikeBean> mayBeLikeData = mRetrofit.create(
                ListTopRetrofitInterface.class).getMayBeLikeData(path);
        return mayBeLikeData;
    }

    @Override
    public Observable<CommentBean> getCommentData(int path) {
        mRetrofit = new Retrofit.Builder()
                .baseUrl(UrlMessage.EVERYDAY_BASE_URL)
                .client(OkHttp3Helper.getOkHttpSingletonInstance())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        Observable<CommentBean> commentBeanData = mRetrofit.create(
                ListTopRetrofitInterface.class).getCommentData(path);
        return commentBeanData;
    }

    @Override
    public Observable<SingleProductBean> getSingleProductData(int path) {
        mRetrofit = new Retrofit.Builder()
                .baseUrl(UrlMessage.EVERYDAY_BASE_URL)
                .client(OkHttp3Helper.getOkHttpSingletonInstance())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        Observable<SingleProductBean> singleProductData = mRetrofit.create(
                ListTopRetrofitInterface.class).getSingleProductData(path);
        return singleProductData;
    }
}
